"use strict";
cc._RF.push(module, '21f54lz8xVGFr8hUOZifK15', 'Toast');
// scripts/common/components/Toast.ts

"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property, executionOrder = _a.executionOrder;
var Toast = /** @class */ (function (_super) {
    __extends(Toast, _super);
    function Toast() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.main = null;
        _this.label = null;
        return _this;
    }
    Toast_1 = Toast;
    Toast.prototype.onLoad = function () {
        this.init();
    };
    Toast.prototype.start = function () {
        this.reset();
    };
    Toast.prototype.onDestroy = function () {
        this.release();
    };
    /**
     * 初始化
     */
    Toast.prototype.init = function () {
        // 设为常驻节点
        cc.game.addPersistRootNode(this.node);
        Toast_1.instance = this;
    };
    /**
     * 释放
     */
    Toast.prototype.release = function () {
        Toast_1.instance = null;
    };
    /**
     * 重置
     */
    Toast.prototype.reset = function () {
        this.main.active = false;
    };
    /**
     * 展示
     * @param texts 内容
     */
    Toast.show = function () {
        var _this = this;
        var texts = [];
        for (var _i = 0; _i < arguments.length; _i++) {
            texts[_i] = arguments[_i];
        }
        return new Promise(function (res) {
            var instance = _this.instance;
            if (!instance) {
                res();
                return;
            }
            var main = instance.main, label = instance.label;
            cc.Tween.stopAllByTarget(main);
            main.opacity = 0;
            main.active = true;
            label.string = texts.join(' ');
            cc.tween(main)
                .to(0.2, { opacity: 200 })
                .delay(2)
                .to(0.2, { opacity: 0 })
                .set({ active: false })
                .call(res)
                .start();
        });
    };
    var Toast_1;
    /** 静态实例 */
    Toast.instance = null;
    __decorate([
        property({ displayName: CC_DEV && '主节点', type: cc.Node })
    ], Toast.prototype, "main", void 0);
    __decorate([
        property({ displayName: CC_DEV && '标签', type: cc.Label })
    ], Toast.prototype, "label", void 0);
    Toast = Toast_1 = __decorate([
        ccclass,
        executionOrder(-101)
    ], Toast);
    return Toast;
}(cc.Component));
exports.default = Toast;

cc._RF.pop();